<?php
/**
 * 《产品管理》实用类
 *
 * @author 孙晓晔
 * @version $Id: MoldUtil.class.php 1035 2010-03-26 05:24:59Z sunxy $
 */
require_once(dirname(__FILE__) . '/../AdminUtil.class.php');

class MoldUtil extends AdminUtil {
	
	function __construct() {
		$request['update'] = '$Date: 2009/03/03 07:24:42 $';
		$request['revision'] = '$Revision: 1.5 $';
			
		parent::__construct($request);
	}

	public $category = array(
		'-' => '请选择',
		'1' => '出口模',
		'2' => '国内模',
		'3' => '注塑',
		'9' => '其它',
	);

	var $piece;
	var $technics;
	var $work;

	function pretreat($controller) {
		parent::pretreat($controller);		

		$this->piece = $this->code_option("2");
		$controller->assign_by_ref('piece_option', $this->piece);

		$this->technics = $this->code_option("3");
		$controller->assign_by_ref('technics_option', $this->technics);

		$this->work = $this->code_option(Constant::tbl_work);
		$controller->assign_by_ref('work_option', $this->work);
		
		$this->t = array_merge($this->t, $this->b);
	}

	public $b = array(
		'car'=>'请输入车辆编号，然后选择并回车即可。',
		'driver'=>'请输入司机姓名拼音首字母，然后选择并回车即可。如张三，输入zs',
	);
	
	function time($controller) {
		$hour_option = array();
		for ($i = 0; $i < 180; $i++) {
			$hour_option[$i] = $i . "小时";
		}

		$minute_option = array();
		for ($i = 0; $i < 60; $i++) {
			if ($i % 5 > 0) {
				continue;
			}
			$minute_option[$i] = $i . "分钟";
		}

		$controller->assign_by_ref('hour_option', $hour_option);
		$controller->assign_by_ref('minute_option', $minute_option);

	}

	function aaaa() {
		$emp = $_SESSION['id'];

		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s where engineer = '%s'";
		$sql = sprintf($fmt, Constant::tbl_mold, $emp);
		// debug($sql);
		$result = $db->query($sql);
		if ($db->num_rows($result) == 0) {
			return '';
		}

		$ret = "in ('000000000";
		while ($row = $db->fetch_array($result)) {
			$ret .= "', '" . $row['id'];
		}

		$ret .= "')";
		$ret = str_replace("'000000000',", '', $ret);

		return $ret;
	}

	/**
	 *
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function delete($controller, $request) {
		$this->pretreat($controller);

		$db = newdb($this->dsn);
		while (list($k, $id) = each($request)) {
			if (substr($k, 0, 2) <> "c_") {
				continue;
			}

			$fmt = "DELETE FROM %s WHERE id = '%s'";
			$sql = sprintf($fmt, $this->tbl, $id);
			// debug($sql);
			$db->query($sql);
		}
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}

	/**
	 * 更新状态
	 *
	 * @param Controller $controller
	 * @param array $request
	 */
	function status($controller, $request) {
		$this->pretreat($controller);

		$id = $request['id'];
		clean($this->tbl . "_id_" . $id);

		$status = $request['status'];

		$db = newdb($this->dsn);
		$fmt = "UPDATE %s SET status = '%s', modifytime = now() WHERE id = '%s'";
		$sql = sprintf($fmt, $this->tbl, $status, $id);
		// debug($sql);
		$db->query($sql);
		
		$controller->assign('baseLink', $this->doGet($request, 'findPost'));

		$this->findPost($controller, $request);
		return true;
	}	
}